import Vue from "vue";
 
//==============================StringUtil=================================
const StringUtil = {
  //是否为空判断
  isNull: function(text) {
    if (undefined == text) {
      return true;
    }
    if (text.length == "" || text.length == 0) {
      return true;
    }
    return false;
  },
  // 过滤一个结果的空记录添加，过滤空搜索
  appendKeywords(searchHistoryList,value) {
    /**
       * 1.已经有的关键词不再添加
       * 2.添加到数组的首位，若超出10个则删除最后一个
       * 3.添加到缓存
       */
      var appendFlag = true;
      if (
        searchHistoryList !== null &&
        searchHistoryList !== undefined &&
        searchHistoryList.length > 0
      ) {
        searchHistoryList.forEach(function(currentValue, index) {
          if (currentValue === value) {
            appendFlag = false;
            return;
          }
        });
        // 判断-添加
        if (appendFlag === true) {
          // 长度判断
          if (searchHistoryList.length >= 10) {
            searchHistoryList.unshift(value);
            searchHistoryList.pop();
          } else {
            searchHistoryList.unshift(value);
          }
          localStorage.setItem(
            "historyItems",
            JSON.stringify(searchHistoryList)
          );
        }
      } else {
        searchHistoryList = [];
        searchHistoryList.push(value);
        localStorage.setItem(
          "historyItems",
          JSON.stringify(searchHistoryList)
        );
      }
  },
};
Vue.prototype.StringUtil = StringUtil;
//==============================StringUtil=================================
 
 
export default {};